package io.xccit.service.impl;

import io.xccit.dao.IBookDao;
import io.xccit.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

/**
 * @author Xccit
 * @Date 2023-02-01
 * @Description
 */
@Service
@Transactional(propagation = Propagation.REQUIRES_NEW)
public class BookServiceImpl implements IBookService {
    @Autowired
    private IBookDao bookDao;
    @Override
    public void buyBook(Integer readerId, Integer bookId) {
        //查询价格
        Integer price = bookDao.getPriceByBookID(bookId);
        //更新库存
        bookDao.updateStock(bookId);
        //更新余额
        bookDao.updateBalance(readerId,price);
        /*System.out.println(1/0); //加入一个运行时异常*/
    }
}
